package cn.iocoder.yudao.module.crm.service.user;

import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 用户 Service 实现类
 *
 * @author 广州氪量
 */
@Service
@Validated
public class UserServiceImpl implements UserService {

    @Resource
    private AdminUserApi adminUserApi;

    @Override
    public Map<Long, String> getUserNamesByIds(Set<Long> userIds) {
        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
        return userMap.values().stream().collect(Collectors.toMap(AdminUserRespDTO::getId, AdminUserRespDTO::getNickname));
    }

    @Override
    public String getUserNamesById(Long userId) {
        return adminUserApi.getUser(userId).getNickname();
    }
}